package com.lin.servlet;

import com.lin.service.BookServiceImpl;
import com.lin.service.IBookService;
import com.lin.utils.BaseServlet;
import com.lin.vo.Book;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@WebServlet(name = "BookServlet", urlPatterns = {"/bookServlet"})
public class BookServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	private IBookService bookService = new BookServiceImpl();

	public String findByAllBook(HttpServletRequest request, HttpServletResponse response) {
		List<Book> bookLists = bookService.findByAllBook();
		request.setAttribute("bookLists", bookLists);
		return "change:/jsps/book/list.jsp";
	}

	public String findByTypeBook(HttpServletRequest request, HttpServletResponse response) {
		String bookType = request.getParameter("cid");
		List<Book> bookLists = bookService.findByTypeBook(bookType);
		request.setAttribute("bookLists", bookLists);
		return "change:/jsps/book/list.jsp";
	}

	public String findByIdBook(HttpServletRequest request, HttpServletResponse response) {
		String bookId = request.getParameter("bid");
		Book book = bookService.findByIdBook(bookId);
		if (book != null) {
			request.setAttribute("book", book);
			return "change:/jsps/book/desc.jsp";
		}
		return "";

	}


}
